/**
 * Description: StudentServiceImpl.java
 * Copyright (c) 2008-2009  Neo. 
 * All Rights Reserved.
 * @version 1.0  Mar 24, 2009 2:38:07 PM 李萌（neolimeng@gmail.com）created
 */
package org.paradise.dms.services.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;

import org.apache.log4j.Logger;
import org.paradise.dms.dao.impl.DormitoryChargeDAOImpl;
import org.paradise.dms.dao.impl.DormitoryDAOImpl;
import org.paradise.dms.dao.impl.StudentDAOImpl;
import org.paradise.dms.pojo.CollegeInfo;
import org.paradise.dms.pojo.DormitoryCharge;
import org.paradise.dms.pojo.MajorInfo;
import org.paradise.dms.pojo.Student;
import org.paradise.dms.services.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.dheaven.framework.dao.DaoException;

/**
 * Description: Copyright (c) 2008-2009 Neo. All Rights Reserved.
 * 
 * @version 1.0 Mar 24, 2009 2:38:07 PM 李萌（neolimeng@gmail.com）created
 */
@Service
public class StudentServiceImpl implements StudentService {

	private static Logger log = Logger.getLogger(DormitoryServiceImpl.class);
	@Autowired
	@Qualifier("studentDAOImpl")
	private StudentDAOImpl studentdaoimpl;
	@Autowired
	@Qualifier("dormitoryDAOImpl")
	private DormitoryDAOImpl dormitoryDAOImpl;
	@Autowired
	@Qualifier("dormitoryChargeDAOImpl")
	private DormitoryChargeDAOImpl dormitoryChargeDAOImpl;

	public DormitoryDAOImpl getDormitoryDAOImpl() {
		return dormitoryDAOImpl;
	}

	public void setDormitoryDAOImpl(DormitoryDAOImpl dormitoryDAOImpl) {
		this.dormitoryDAOImpl = dormitoryDAOImpl;
	}

	public boolean insertStudent(Student student) {
		try {
			this.studentdaoimpl.insertStudent(student);
			return true;
		} catch (Exception e) {
			log.error("插入学生记录时出错!!");
			e.printStackTrace();
			return false;
		}
	}
	
	public int batchInsert(List<Student> list) {
		return studentdaoimpl.batchInsert(list);
	}
	
	public boolean updateStudent(Student student) {
		try {
			this.studentdaoimpl.updateStudent(student);
			return true;
		} catch (Exception e) {
			log.error("更新学生记录时出错!!");
			e.printStackTrace();
			return false;
		}
	}

	public boolean deleteStudent(int studentid) {
		try {
			this.studentdaoimpl.deleteStudent(studentid);
			return true;
		} catch (Exception e) {
			log.error("删除学生记录时出错!!");
			e.printStackTrace();
			return false;
		}
	}

	public Student getStudent(int studentid) {
		try {

			return this.studentdaoimpl.getStudent(studentid);
		} catch (Exception e) {
			log.error("根据学生ID取得学生记录时出错!!");
			e.printStackTrace();
			return null;
		}
	}

	public List<Student> getAllStudentPerPage(int pageSize, int startRow) {
		try {
			return this.studentdaoimpl.getAllStudentPerPage(pageSize, startRow);
		} catch (Exception e) {
			log.error("取得全部学生记录时出错!!");
			e.printStackTrace();
			return null;
		}
	}

	public List<Student> getStudentByStudentNo(String studentno) {
		try {
			return this.studentdaoimpl.getStudentByStudentNoForDimStudentInfoSearch(studentno);
		} catch (Exception e) {
			log.error("Service层：根据学号取得学生信息时出错");
			e.printStackTrace();
			return null;
		}
	}

	public List<Student> searchStudentByStudentName(String name, int pageSize, int startRow) throws DaoException {
		return studentdaoimpl.searchStudentByStudentName(name, pageSize, startRow);
	}

	public StudentDAOImpl getStudentdaoimpl() {
		return studentdaoimpl;
	}

	public void setStudentdaoimpl(StudentDAOImpl studentdaoimpl) {
		this.studentdaoimpl = studentdaoimpl;
	}

	public List<Student> getStudentBySQLSearchConditions(String searchstudentsql) {
		return studentdaoimpl.findStudentBySQLSearchConditions(searchstudentsql);
	}

	public List<MajorInfo> getAllMajorInfo() {
		return studentdaoimpl.findAllMajorInfo();

	}

	public List<MajorInfo> getMajorInfoByCollegeId(String collegeinfoid) {
		return studentdaoimpl.findMajorInfoBySQLSearchConditions(collegeinfoid);
	}

	public List<CollegeInfo> getCollegeInfoByMajorId(String majorinfoid) {
		return studentdaoimpl.findCollegeInfoBySQLSearchConditions(majorinfoid);
	}

	public List<CollegeInfo> getAllcollegeInfo() {
		return studentdaoimpl.findAllCollegeInfo();

	}

	@SuppressWarnings("unchecked")
	public List getStudentBySQLSearchConditions(String searchstudentsql, int pageSize, int startRow) {
		return studentdaoimpl.findStudentBySQLSearchConditions(searchstudentsql, pageSize, startRow);
	}

	public int getStudentBySQLSearchConditionsRows(String searchstudentsql) {
		return studentdaoimpl.findStudentBySQLSearchConditionsRows(searchstudentsql);
	}

	public String UpdateBatchStudentpreassignedID(String[] studentid ,String studentpreassignid) {
		return studentdaoimpl.UpdateBatchStudentpreassignedID(studentid,studentpreassignid);
	}

	public int updateAllStudentPreasignedidAtService(String sql) {
		return this.studentdaoimpl.updateAllStudentPreasignedidAtDAO(sql);
	}

	public int getAllStudentRows() {
		return studentdaoimpl.getAllStudentsRows();
	}

	public List<Student> getStudentByStudentPreID(String studentpreallocationid, int pageSize, int startRow) {
		return studentdaoimpl.getStudentPerPageByPreID(studentpreallocationid, pageSize, startRow);
	}

	public int getStudentByStudentPreIDRows(String studentpreallocationid) {
		return this.studentdaoimpl.getStudentByStudentPreIDRows(studentpreallocationid);
	}

	@SuppressWarnings("unchecked")
	public List getStudentInfoByDormitoryID(String dormitoryid) {
		return dormitoryDAOImpl.getStudentInfoByDormitoryID(dormitoryid);
	}

	@SuppressWarnings("unchecked")
	public List getStudentBasicInfo(String studentno,int studentdormitorytype) {
		return studentdaoimpl.getStudentBasicInfo(studentno,studentdormitorytype);
	}

	public int getAllStudentRowsByStudentNo(String[] studentno) {
		return studentdaoimpl.getAllStudentRowsByStudentNo(studentno);
	}

	public List<Student> getAllStudentPerPageByStudentNo(String[] studentno, int pageSize, int startRow) {
		return studentdaoimpl.getAllStudentPerPageByStudentNo(studentno, pageSize, startRow);
	}
	
	@SuppressWarnings("unchecked")
	public List<Student> getAllStudentByStudentId(String[] studentid){
		return studentdaoimpl.getAllStudentByStudentId(studentid);
	}


	@SuppressWarnings("unchecked")
	public List studentInfoForExportToExcel(String stringOfStuIdArray) {
		return studentdaoimpl.studentInfoForExportToExcel(stringOfStuIdArray);
	}
	public List studentInfoForExportToExcel2(String stringOfStuIdArray) {
		return studentdaoimpl.studentInfoForExportToExcel2(stringOfStuIdArray);
	}

	/**
	 * 
	 * Description: 查询学生的历史住宿信息
	 * 
	 * @Version1.0 Apr 17, 2009 3:22:32 PM 郑旭（zhengxu2006@gmail.com）创建
	 * @param studentno
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List getStudentHistoryAccomodationInfo(String studentno,int studentdormitorytype) {
		return studentdaoimpl.getStudentHistoryAccomodationInfo(studentno,studentdormitorytype);
	}

	@SuppressWarnings("unchecked")
	public List searchStudentByStudentDimNo(String dimno, int pageSize, int startRow) {
		return studentdaoimpl.searchStudentByStudentDimNo(dimno, pageSize, startRow);
	}

	public boolean updateStudentChargeInfo(String studentid, String preenrollyear, String postenrollyear) {
		List<DormitoryCharge> list;
		try {
			list = dormitoryChargeDAOImpl.getDormitoryChargeByStudentId(studentid);
		} catch (DaoException e) {
			log.equals("DMS_error:更新学生" + studentid + "交费信息失败！");
			return false;
		}
		return true;
	}

	public DormitoryChargeDAOImpl getDormitoryChargeDAOImpl() {
		return dormitoryChargeDAOImpl;
	}

	public void setDormitoryChargeDAOImpl(DormitoryChargeDAOImpl dormitoryChargeDAOImpl) {
		this.dormitoryChargeDAOImpl = dormitoryChargeDAOImpl;
	}

	@SuppressWarnings("unchecked")
	public List getStudentBySQL(String searchstudentsql) {
		return studentdaoimpl.getStudentBySQL(searchstudentsql);
	}
	@SuppressWarnings("unchecked")
	public List getStudentTelBySQL(String searchstudentsql) {
		return studentdaoimpl.getStudentTelBySQL(searchstudentsql);
	}

	@SuppressWarnings("unchecked")
	public List getStudentChargeRecord(String studentno,int studentdormitorytype) {
		return studentdaoimpl.getStudentChargeRecord(studentno,studentdormitorytype);
	}

	public int searchStudentByStudentDimNoTotalRows(String dimno) {
		return studentdaoimpl.searchStudentByStudentDimNoTotalRows(dimno);

	}

	public int searchStudentByStudentNameTotalRows(String studentname) {
		return studentdaoimpl.searchStudentByStudentNameTotalRows(studentname);
	}

	public int isExistStu(String arg, String field) {
		return studentdaoimpl.isExistStu(arg, field);
	}

	public String[][] getStudentIDListByStudentPreID(String studentpreallocationid) {
		return studentdaoimpl.getStudentIDListByStudentPreID(studentpreallocationid);
	}
	public boolean isExist(String table,String field , String value){
		return studentdaoimpl.isExist(  table,  field ,   value);
	}
	public boolean editStuMsc(String msc,String stuno){
		return studentdaoimpl.editStuMsc(  msc,  stuno);
	}
	public List batchUpdate(List list){
		System.out.println(list.size());
		List l = new ArrayList();
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = (Object[]) list.get(i);
			//if(i ==1){
				String str = studentdaoimpl.getxinStudentnoByStudentno(obj);
				//String str1 = studentdaoimpl.updateStudentCollegeinfoByStudentno(obj);
				System.out.println(i+"---"+obj[2].toString()+"---"+str+"---");
				if(!"ok".equals(str)){
					obj[5] = str;
					l.add(obj);
				}
			//}
		}
		return l;
	}
	
	public int getCollegeIdByName(String name){
		return studentdaoimpl.getCollegeIdByName(name);
	}
	public String getCollegeNameById(int id){
		return studentdaoimpl.getCollegeNameById(id);
	}
	public boolean insertCollege(String collegename){
		return studentdaoimpl.insertCollege(collegename);
	}
	public boolean deleteCollege(int collegeid){
		return studentdaoimpl.deleteCollege(collegeid);
	}
	public int updateCollege(int collegeid,String collegename){
		return studentdaoimpl.updateCollege(collegeid,collegename);
	}
	public boolean insertMajor(int collegeid,String majorname){
		return studentdaoimpl.insertMajor(collegeid,majorname);
	}
	public boolean deleteMajor(int majorid){
		return studentdaoimpl.deleteMajor(majorid);
	}
	public int updateMajor(int majorid,String majorname){
		return studentdaoimpl.updateMajor(majorid,majorname);
	}

	public HashSet<String> getStudentNo() {
		
		return studentdaoimpl.getStudentNo();
	}
}
